/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package id3.UIs;

import java.awt.CardLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 *
 * @author NguyenVan
 */
public class HocmayFrame extends JFrame implements ActionListener{
    private static HocmayFrame instansce;

    public static HocmayFrame getInstansce() {
        if(instansce==null)
            new HocmayFrame();
        return instansce;
    }
    
    private final MainPanel _MainPanel=new MainPanel();
    public HocmayFrame() throws HeadlessException {
        instansce=this;
        setTitle("He Thong phan loai khach hang");
        setSize(600,600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JMenuBar jMenuBar=new JMenuBar();
        JMenu jMenuFile=new JMenu("Files");
        JMenuItem jMenuItemConfig=new JMenuItem("Random training set");
        JMenuItem jMenuItemTrain=new JMenuItem("Training");
        JMenuItem jMenuItemTest=new JMenuItem("Test");
        
        jMenuFile.add(jMenuItemTrain);
        jMenuFile.add(jMenuItemTest);
        jMenuFile.add(jMenuItemConfig);
        JMenu jMenuHelp=new JMenu("Help");
        jMenuBar.add(jMenuFile);
        jMenuBar.add(jMenuHelp);
        setJMenuBar(jMenuBar);
        setVisible(true);
        setLayout(new CardLayout());
        setLocationRelativeTo(null);
        add(_MainPanel);
        jMenuItemConfig.addActionListener( this);
        jMenuItemTest.addActionListener(this);
        jMenuItemTrain.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(null != e.getActionCommand())switch (e.getActionCommand()) {
            case "Random training set":{
                CardLayout layout=(CardLayout)_MainPanel.getLayout();
                layout.show(_MainPanel, MainPanel.RANDOM_PANEL);
                break;
                }
            case "Training":{
                CardLayout layout=(CardLayout)_MainPanel.getLayout();
                layout.show(_MainPanel, MainPanel.TRAINING_PANEL);
                break;
                }
            case "Test":{
                CardLayout layout=(CardLayout)_MainPanel.getLayout();
                layout.show(_MainPanel, MainPanel.TEST_PANEL);
                break;
                }
        }
    }   
}
